import Vue from 'vue'
import store from './store'
import App from './App'
import './js_sdk/ican-H5Api/ican-H5Api.js' //h5粘贴板
const msg = (title, duration = 1500, mask = false, icon = 'none') => {
	//统一提示方便全局修改
	if (Boolean(title) === false) {
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}


const showLoading = (title = '加载中...', mask = true) => {
	uni.showLoading({
		title: title,
		mask: mask
	})
}

const hideLoading = () => {
	uni.hideLoading();
}

const previewImage = (arr = [],current = 0) => {
	return uni.previewImage({
		current: current,
		urls: [...arr]
	});
}

const json = type => {
	//模拟异步请求数据
	return new Promise(resolve => {
		setTimeout(() => {
			resolve(Json[type]);
		}, 500)
	})
}

const prePage = () => {
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	// #ifdef H5
	return prePage;
	// #endif
	return prePage.$vm;
}


Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;

//共通方法
import globalUtil from './common/globalUtil.js'
Vue.prototype.$api = {
	msg,
	showLoading,
	hideLoading,
	json,
	prePage,
	globalUtil,
	previewImage
};

App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
